<?php

/**
 * Discount form.
 *
 * @package    photobook
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class DiscountForm extends BaseDiscountForm
{
  protected static $discount_types = array('Giảm giá theo số lượng', 'Giảm giá theo sự kiện');  
    
  public function configure()
  {
    $subForm = new sfForm();
    $discountDetail = new DiscountDetail();
    $discountDetail->Discount = $this->getObject();
    $form = new DiscountDetailForm($discountDetail);
    $subForm->embedForm('Detail', $form);
    
    $this->setWidgets(array(
      'id'               => new sfWidgetFormInputHidden(),
      'discount_type'    => new sfWidgetFormSelect(array('choices' => self::$discount_types)),
      'title'            => new sfWidgetFormInputText(),
      'content'          => new sfWidgetFormTextareaTinyMCECustom(array('width'   => 500,'height'  => 300,)),
      'from_date'        => new sfWidgetFormJQueryDate(array('image' => '/images/calendar_edit.png', 'config' => '{}',)),
      'to_date'          => new sfWidgetFormJQueryDate(array('image' => '/images/calendar_edit.png', 'config' => '{}',)),
      'discount_status'  => new sfWidgetFormInputCheckbox(),
      'banner'           => new sfWidgetFormInputFileEditable(array(
          'label'     =>     'Banner',
          'file_src'  =>     '/uploads/discount/'.$this->getObject()->getBanner(),
          'is_image'  =>     true,
          'edit_mode' =>    !$this->isNew(),
          'template'  =>    '<div>%file%<br />%input%<br />%delete%%delete_label%</div>',    
      )),
      'is_view_homepage' => new sfWidgetFormInputCheckbox(),
    ));
    
    $this->validatorSchema['banner_delete'] = new sfValidatorPass();
    
    $this->setValidators(array(
      'id'               => new sfValidatorChoice(array('choices' => array($this->getObject()->get('id')), 'empty_value' => $this->getObject()->get('id'), 'required' => false)),
      'discount_type'    => new sfValidatorChoice(array('choices' => array_keys(self::$discount_types))),
      'title'            => new sfValidatorString(array('max_length' => 255)),
      'content'          => new sfValidatorString(array('max_length' => 4000)),
      'from_date'        => new sfValidatorDate(),
      'to_date'          => new sfValidatorDate(),
      'discount_status'  => new sfValidatorBoolean(array('required' => false)),
      'banner'           => new sfValidatorFile(array('mime_types' => 'web_images','path' => sfConfig::get('sf_upload_dir').'/discount', 'required' => false)),
      'is_view_homepage' => new sfValidatorBoolean(array('required' => false)),
    ));
    
    $this->widgetSchema->setNameFormat('discount[%s]');
    
    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    $this->setupInheritance();
    
    $this->embedForm('Thông tin khuyến mãi', $subForm);
  }
}
